Add some simple tests for cross compilation
authorAlex Crichton <alex@alexcrichton.com>
Fri, 11 Jul 2014 16:08:51 +0000 (09:08 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 11 Jul 2014 16:08:51 +0000 (09:08 -0700)
tests/support/mod.rs
tests/test_cargo_cross_compile.rs [new file with mode: 0644]
tests/tests.rs

index 90a3542ff912e2344360992381b21f754ae55d31..fd99e08d8ceb18e7c5ced11ca43425b2eaf38f8f 100644 (file)
@@ -101,6 +101,11 @@ impl ProjectBuilder {
         self.build_dir().join(format!("{}{}", b, os::consts::EXE_SUFFIX))
     }
 
+    pub fn target_bin(&self, target: &str, b: &str) -> Path {
+        self.build_dir().join(target).join(format!("{}{}", b,
+                                                   os::consts::EXE_SUFFIX))
+    }
+
     pub fn build_dir(&self) -> Path {
         self.root.join("target")
     }
diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs
new file mode 100644 (file)
index 0000000..4bc4ddc
--- /dev/null
@@ -0,0 +1,78 @@
+// Currently the only cross compilers available via nightlies are on linux/osx,
+// so we can only run these tests on those platforms
+#![cfg(target_os = "linux")]
+#![cfg(target_os = "macos")]
+
+use std::os;
+
+use support::{project, execs, basic_bin_manifest};
+use hamcrest::{assert_that, existing_file};
+use cargo::util::process;
+
+fn setup() {
+}
+
+fn alternate() -> &'static str {
+    match os::consts::SYSNAME {
+        "linux" => "i686-unknown-linux-gnu",
+        "darwin" => "i686-apple-darwin",
+        _ => unreachable!(),
+    }
+}
+
+test!(simple_cross {
+    let p = project("foo")
+        .file("Cargo.toml", basic_bin_manifest("foo").as_slice())
+        .file("src/foo.rs", r#"
+            use std::os;
+            fn main() {
+                assert_eq!(os::consts::ARCH, "x86");
+            }
+        "#);
+
+    let target = alternate();
+    assert_that(p.cargo_process("cargo-build").arg("--target").arg(target),
+                execs().with_status(0));
+    assert_that(&p.target_bin(target, "foo"), existing_file());
+
+    assert_that(
+      process(p.target_bin(target, "foo")),
+      execs().with_status(0));
+})
+
+test!(simple_deps {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies.bar]
+            path = "../bar"
+        "#)
+        .file("src/main.rs", r#"
+            extern crate bar;
+            fn main() { bar::bar(); }
+        "#);
+    let p2 = project("bar")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "pub fn bar() {}");
+    p2.build();
+
+    let target = alternate();
+    assert_that(p.cargo_process("cargo-build").arg("--target").arg(target),
+                execs().with_status(0));
+    assert_that(&p.target_bin(target, "main"), existing_file());
+
+    assert_that(
+      process(p.target_bin(target, "main")),
+      execs().with_status(0));
+})
+
+
index bb5bf97395436a1970c0b022b21bc4b1010f12e7..595287a18da3ed16e4b1cfae048bec52f503df17 100644 (file)
@@ -26,3 +26,4 @@ mod test_cargo_compile_git_deps;
 mod test_cargo_compile_path_deps;
 mod test_cargo_test;
 mod test_shell;
+mod test_cargo_cross_compile;